<?php

require_once dirname(__FILE__) . '/../lib/celebrityVoteGeneratorConfiguration.class.php';
require_once dirname(__FILE__) . '/../lib/celebrityVoteGeneratorHelper.class.php';

/**
 * celebrityVote actions.
 *
 * @package    iEasy
 * @subpackage celebrityVote
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class celebrityVoteActions extends autoCelebrityVoteActions
{
    public function executeFilterCelebrity($request)
    {
        $this->getResponse()->setContentType('application/json');
        $celebrityEntities = Doctrine_Core::getTable("celebrity")->createQuery('c')
                ->addWhere('status_id=?', 1005)
                ->addWhere('name like ?', '%' . $request->getParameter('q') . '%')
                ->addOrderBy('celebrity_id desc')->limit($request->getParameter('limit'))
                ->execute();
        $celebritys = array();
        foreach ($celebrityEntities as $celebrity) {
            $celebritys[$celebrity->getCelebrityId()] = (string)$celebrity;
        }
        return $this->renderText(json_encode($celebritys));
    }


    public function executeBatchClearVote(sfWebRequest $request)
    {
        $ids = $request->getParameter('ids');
        $q = Doctrine_Core::getTable('Celebrityvote')->createQuery('c')
                ->whereIn('c.id', $ids);
        foreach ($q->execute() as $vote) {
            $vote->setVoteI(0);
            $vote->save();
        }
        $this->getUser()->setFlash('notice', '选定的用户投票已清空.');
        $this->redirect('celebrityvote');
    }

    public function executeBatchClearVoteMask(sfWebRequest $request)
    {
        $ids = $request->getParameter('ids');
        $q = Doctrine_Core::getTable('Celebrityvote')->createQuery('c')
                ->whereIn('c.id', $ids);
        foreach ($q->execute() as $vote) {
            $vote->setVoteMaskI(0);
            $vote->save();
        }
        $this->getUser()->setFlash('notice', '选定的投票修正值已清空.');
        $this->redirect('celebrityvote');
    }


    public function executeListClearAllVote(sfWebRequest $request)
    {
        $q = Doctrine_Core::getTable('Celebrityvote')->createQuery('c');
        foreach ($q->execute() as $vote) {
            $vote->setVoteI(0);
            $vote->save();
        }
        $this->getUser()->setFlash('notice', '用户投票已清空.');
        $this->redirect('celebrityvote');
    }

    public function executeListClearAllVoteMask(sfWebRequest $request)
    {
        $q = Doctrine_Core::getTable('Celebrityvote')->createQuery('c');
        foreach ($q->execute() as $vote) {
            $vote->setVoteMaskI(0);
            $vote->save();
        }
        $this->getUser()->setFlash('notice', '投票修正值已清空.');
        $this->redirect('celebrityvote');
    }

    public function executeListClearVote(sfWebRequest $request)
    {
        $vote = $this->getRoute()->getObject();
        $vote->setVoteI(0);
        $vote->save();
        $this->getUser()->setFlash('notice', $vote->getCelebrity()->getName() . '的用户投票已清空.');
        $this->redirect('celebrityvote');
    }

    public function executeListClearVoteMask(sfWebRequest $request)
    {
        $vote = $this->getRoute()->getObject();
        $vote->setVoteMaskI(0);
        $vote->save();
        $this->getUser()->setFlash('notice', $vote->getCelebrity()->getName() . '的投票修正值已清空.');
        $this->redirect('celebrityvote');
    }
}
